package com.m8android.backup;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.HandlerBase;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.ContentProviderOperation;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.AlteredCharSequence;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;



public class BackupList extends ListActivity {
    /** Called when the activity is first created. */
	
	private String m_BackupDir = "/sdcard/backup/";

	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.backuplist);
        
        String[] backupList = getBakcupList();
        ListAdapter listAdapter = new ArrayAdapter<String>(this, R.layout.list_row, backupList);
        
        setListAdapter(listAdapter);
    }
    
    private String[] getBakcupList()
    {
    	String[] result;
    	File backupDir = new File(m_BackupDir);
    	if(backupDir.isDirectory())
    		result = backupDir.list();
    	else
    		result = new String[0];
    	return result;
    }

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		
		ArrayAdapter<String> listAdapter = (ArrayAdapter<String>)getListAdapter();
		if(listAdapter == null)
			return;

		String backupDirName = listAdapter.getItem((int)id);
		
		Intent i = new Intent(this, BackupItemSelection.class);
		i.putExtra(BackupItemSelection.PREFIX_DIR,  m_BackupDir + backupDirName);
		startActivity(i);
		
	}
}